package top.drose;

import java.util.Scanner;
import java.util.Stack;

/// https://acm.hdu.edu.cn/showproblem.php?pid=1062
/// stack的使用：字符串反转
public class P17_1 {
    static Scanner sc = new Scanner(System.in);
    static Stack<Character> s=new Stack<>();
    public static void main(String[] args) {
        int n=sc.nextInt();
        while(n!=0){
            s.empty();
            while(true){
                char ch=sc.next().charAt(0);
                if(ch==' '||ch=='\n'||!sc.hasNext()){
                    while(!s.isEmpty()){
                        System.out.printf("%c",s.pop());
                    }
                    if(ch=='\n'||!sc.hasNext()){
                        break;
                    }
                    System.out.printf(" ");
                }else{
                    s.push(ch);
                }
            }
            System.out.println();
            n--;
        }

    }
}
